using GammaJul.ReSharper.GammaXaml.Highlightings.CSharp;
using JetBrains.Annotations;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Daemon;
using JetBrains.ReSharper.Psi;

[assembly: RegisterConfigurableSeverity(
	OwnerMustBeDependencyObjectHighlighting.SeverityId,
	null,
	HighlightingGroupIds.CodeSmell,
	OwnerMustBeDependencyObjectHighlighting.Description,
	OwnerMustBeDependencyObjectHighlighting.Description,
	Severity.ERROR,
	false)]

namespace GammaJul.ReSharper.GammaXaml.Highlightings.CSharp {

	/// <summary>
	/// An highlighting that represent a DependencyProperty.Register()-like call with an owner type
	/// that doesn't derive from DependencyObject.
	/// </summary>
	[ConfigurableSeverityHighlighting(SeverityId, CSharpProjectFileType.Name, OverlapResolve = OverlapResolveKind.ERROR)]
	public class OwnerMustBeDependencyObjectHighlighting : IHighlighting {
		internal const string SeverityId = "Dp.OwnerMustBeDependencyObject";
		internal const string Description = "Dependency property owner must be a DependencyObject.";

		private readonly IClass _ownerClass;
	
		/// <summary>
		/// Gets the owner type class.
		/// </summary>
		[CanBeNull]
		public IClass OwnerClass {
			get { return _ownerClass; }
		}

		public string ToolTip {
			get { return Description; }
		}

		public string ErrorStripeToolTip {
			get { return Description; }
		}

		public int NavigationOffsetPatch {
			get { return 0; }
		}

		public bool IsValid() {
			return _ownerClass == null || _ownerClass.IsValid();
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="OwnerMustBeDependencyObjectHighlighting"/> class.
		/// </summary>
		/// <param name="ownerClass">The owner type class.</param>
		public OwnerMustBeDependencyObjectHighlighting([CanBeNull] IClass ownerClass) {
			_ownerClass = ownerClass;
		}
	}

}
